import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//创建store对象
const store=new Vuex.Store({
    state:{
        num:10
    },
    mutations:{
        INCREMENT_NUM(state,payload){
            state.num=state.num+payload
        }
    },
    getters:{
       doubleNum(state){
         return 2*state.num
       } 
    },
    actions:{
        incrementAsync(cxt,payload){
            setTimeout(() => {
                cxt.commit('INCREMENT_NUM',payload)
            }, 3000);
        }
    }
})
export default store